{% extends 'base.html' %}

{% block stylesheets %}
    <link rel="stylesheet" type="text/css" href="/static/lib/DataTables-1.10.3/media/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="/static/lib/DataTables-1.10.3/media/bootstrap/2/dataTables.bootstrap.css">
{% endblock %}

{% block all_content %}
    <div class="page-header">
        <h1>Join a group</h1>
    </div>
    <div>
        {{ join_group_text.html|safe }}
    </div>

    <table id="join-group-table" class="table table-hover">
        <thead>
            <tr>
                <th>Group</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            {% for group in groups %}
                <tr>
                    <form action="." method="post">
                        {% csrf_token %}
                        <input type="hidden" name="group_id" value="{{ group.id }}">
                        <td>
                            <h4>{{ group.name }}</h4>
                        </td>
                        <td>
                            <button type="submit" class="btn btn-primary">Join</button>
                        </td>
                    </form>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    <p />
{% endblock %}

{% block scripts %}
    <script type="text/javascript" src="/static/lib/DataTables-1.10.3/media/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="/static/lib/DataTables-1.10.3/media/bootstrap/2/dataTables.bootstrap.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('#join-group-table').DataTable( {
                "bLengthChange": false,
                "aoColumns": [
                    null,
                    { "bSortable": false, "bSearchable": false } // Disable search matching and sorting for 2nd column.
                ]
            });

            var SEARCH_FIELD = $(".dataTables_filter").find("input");
            SEARCH_FIELD.attr("placeholder", "Type something...");
            SEARCH_FIELD.addClass("search-query");
        });
    </script>

{% endblock %}
